import { ref, onMounted, onUnmounted, inject } from "vue";
const useChart = () => {
    let allData = ref(null);
    let chartInstance = null;
    const chart_ref = null;
    //初始化
    const initChart = () => {
        //挂载chart
        chartInstance = inject("chart").init(chart_ref);
        /** @type EChartsOption */
        const initOption = {};
        chartInstance.setOption(initOption);
    };
    //更新
    const getData = async () => {
        // 获取数据
        const { data: ret } = await inject("http").get("/api/rank");
        allData.value = ret;
        console.log(allData.value);
        upDataChart();
    };
    //获取数据
    const upDataChart = () => {
        //处理数据

        /** @type EChartsOption */
        const dataOption = {};
        chartInstance.setOption(dataOption);
    };
    // 响应式适配
    const screenAdapt = () => {
        //标题文字
        const titleFontSize = chart_ref.offsetWidth * (66 / 1536);
        console.log(titleFontSize);
        /** @type EChartsOption */
        const adaptOption = {};
        chartInstance.setOption(adaptOption);
        chartInstance.resize();
    };
    onMounted(() => {
        initChart();
        getData();
        window.addEventListener("resize", screenAdapt);
        screenAdapt();
    });
    onUnmounted(() => {
        window.removeEventListener("resize", screenAdapt);
    });
};